package com.jsoft.dao.impl;

import com.jsoft.dao.EnterpriseDao;
import com.jsoft.entity.Enterprise;
import com.jsoft.utils.DAO;

import java.util.List;

/**EnterpriseDao实现类
 * @author snkstart
 * @create 2023-02-20 20:12
 */
public class EnterpriseDaoImpl extends DAO<Enterprise> implements EnterpriseDao {

    /**
     * 查询所有的企业
     * @return  返回所有的企业
     * @throws Exception
     */
    @Override
    public List<Enterprise> selectEnterprise() throws Exception {
        String sql="select id, name from enterprise";
        return getForList(sql);
    }


    /**
     * 
     * @param EnterpriseName
     * @return
     * @throws Exception
     */
    @Override
    public String selectEnterpriseCodeByName(String EnterpriseName) throws Exception {
        String sql="SELECT social_uniform_code socialUniformCode FROM enterprise WHERE NAME=?";
        return getForValue(sql,EnterpriseName);
    }




    /**
     * 根据企业id查询企业名和社会统一代码
     * @param id 企业id
     * @return 返回企业名和社会统一代码
     * @throws Exception 将所有异常抛到servlet层
     */
    @Override
    public Enterprise findEnterpriseById(Integer id) throws Exception {
        String sql = "SELECT name,social_uniform_code socialUniformCode FROM enterprise WHERE id = ?";
        return get(sql,id);
    }

}
